#include "pointcloud_tools.h"
#include <iostream>
#include "point_common.h"
#include <fstream>
using namespace  pointcloud_tools;

int main(int argc, char** argv) {
    Pointcloud_utils ptu_offline;  
    Pointcloud_online_utils ptu_online;
    ptu_online.pmem_mmap_init();
    ptu_offline.ddrSize = 8 * 8 * 1024 * 1024 * sizeof(int); //256MB
    assert(ptu_offline.Model_DDR_alloc("DDR_32MB.bin"));

    ptu_online.DDR_BASE_ADDR = 0x95000000;
    ptu_offline.DDR_BASE_ADDR = 0x95000000;

    ptu_online.layer_config.cfg_inch_loop_num   = 0;
    ptu_online.layer_config.cfg_core_enable = 0xf; // 32 output channels
    ptu_online.layer_config.cfg_shift_num = 8;  
    ptu_online.layer_config.BASE_WT_ADDR = ptu_online.DDR_BASE_ADDR;

    ptu_offline.layer_config.cfg_inch_loop_num   = 0;
    ptu_offline.layer_config.cfg_core_enable = 0xf; // 32 output channels
    ptu_offline.layer_config.cfg_shift_num = 8;  
    ptu_offline.layer_config.BASE_WT_ADDR = ptu_online.DDR_BASE_ADDR;



    
    BlockConfig bcfg;

    uint16_t valid_pt_num = 200;
    bcfg.cfg_cam_valid_num = valid_pt_num;
    bcfg.cfg_total_point_num = valid_pt_num;
    bcfg.BASE_PT_ADDR = 0x96000000;
    bcfg.BASE_IN_ADDR = 0x97000000;
    bcfg.BASE_RS_ADDR = 0x98000000;

    ptu_offline.block_config.push_back(bcfg);
    ptu_online.block_config.push_back(bcfg);
    ptu_offline.Model_RandomDataGenerator();

    size_t dlen_pt = readBinToVec(ptu_offline.block_config[0].pt_data, "./RunsFiles_offline/point_block_000000.bin");
    assert(dlen_pt > 0);
    size_t dlen_in = readBinToVec(ptu_offline.block_config[0].in_data, "./RunsFiles_offline/input_block_000000.bin");
    assert(dlen_in > 0);

    dlen_pt = readBinToVec(ptu_online.block_config[0].pt_data, "./RunsFiles_offline/point_block_000000.bin");
    assert(dlen_pt > 0);
    dlen_in = readBinToVec(ptu_online.block_config[0].in_data, "./RunsFiles_offline/input_block_000000.bin");
    assert(dlen_in > 0);

    size_t dlen1 = readBinToVec(ptu_online.layer_config.wt_data, "./RunsFiles_offline/weight.bin");
    assert(dlen1 > 0);
    dlen1 = readBinToVec(ptu_offline.layer_config.wt_data, "./RunsFiles_offline/weight.bin");
    assert(dlen1 > 0);
    

    ptu_offline.wt_init();
    ptu_offline.compute_init();
    ptu_offline.run();

    ptu_online.wt_init();
    ptu_online.compute_init();
    ptu_online.run();
 
    ptu_offline.Model_DDR_close(); // Close the simulated DDR file

}

  



